home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / NCSA / tn3270 2.4d7 source / tn3270 / addsw.c next >
C/C++ Source or Header  |  1992-04-17  |  4KB  |  129 lines

  1. /*
  2.  *  tn3270 for the Macintosh Source Code
  3.  *  Brown University Computing and Information Services
  4.  *  Version 2.4d7  April, 1992
  5.  *  Copyright (c) 1988, 1989, 1990, 1991, 1992 by Brown University and by
  6.  *  Peter John DiCamillo.
  7.  *
  8.  *  Permission is granted to any individual or institution to use, copy,
  9.  *  or redistribute the binary version of this software and its
  10.  *  documentation provided this notice and the copyright notices are
  11.  *  retained.  Permission is granted to any individual or non-profit
  12.  *  institution to use, copy, modify, or redistribute the source files
  13.  *  of this software provided this notice and the copyright notices are
  14.  *  retained.  This software may not be distributed for profit, either
  15.  *  in original form or in derivative works, nor can the source be
  16.  *  distributed to other than an individual or a non-profit institution.
  17.  *  Any  individual or group interested in seeing and/or using these
  18.  *  source files but who are prevented from doing so by the above
  19.  *  constraints should contact Don Wolfe, Assistant Vice-President for
  20.  *  Computer Systems at Brown University, (401) 863-7250, for possible
  21.  *  software licensing of the source developed at Brown.
  22.  *
  23.  *  Brown University and Peter John DiCamillo make no representations
  24.  *  about the suitability of this software for any purpose.
  25.  *
  26.  *  BROWN UNIVERSITY AND PETER JOHN DICAMILLO GIVE NO WARRANTY, EITHER
  27.  *  EXPRESS OR IMPLIED, FOR THE PROGRAM AND/OR DOCUMENTATION PROVIDED,
  28.  *  INCLUDING, WITHOUT LIMITATION, WARRANTY OF MERCHANTABILITY AND
  29.  *  WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE.
  30.  *
  31.  */
  32.  
  33. #include "maclib.h"
  34.  
  35. main(argc, argv)
  36. int argc; unsigned char * argv[];
  37. {
  38. OSErr rc;
  39. short vref, fref, sizeattrs;
  40. long fsize;
  41. Handle sizehandle;
  42. struct {
  43.     short flags;
  44.     long prefsize;
  45.     long minsize;
  46.     } sizersc;
  47. unsigned char fname[128];
  48. char test;
  49.  
  50. if (argc < 2) {
  51.     printf("A fileid must be specified to addswt\n");
  52.     return;
  53.     }
  54. strcpy(fname, argv[1]);
  55. c2pstr(fname);
  56. test = argc > 2;
  57.  
  58. /* get size of tn3270 resource fork */
  59. vref = 0;
  60. rc = OpenRF(fname, vref, &fref);
  61. if (rc != 0) {
  62.     printf("Error %d from OpenRF.\n", rc);
  63.     return(rc);
  64.     }
  65. rc = GetEOF(fref, &fsize);
  66. FSClose(fref);
  67. if (rc != 0) {
  68.     printf("Error %d from GetEOF.\n", rc);
  69.     return(rc);
  70.     }
  71.  
  72. /* construct switcher resource to be added */
  73.  
  74. sizersc.flags = 0x5880;
  75. sizersc.prefsize = (((fsize+102400L+1023L)/1024L) + 100) << 10;
  76. sizersc.minsize = (((fsize+102400L+1023L)/1024L) + 61) << 10;
  77. if (test) sizersc.prefsize += (270 << 10);
  78.  
  79. /* add new resource to tn3270 */
  80. fref = OpenResFile(fname);
  81. rc = ResError();
  82. if (rc != 0) {
  83.     printf("Error %d from OpenResFile.\n", rc);
  84.     return(rc);
  85.     }
  86. sizehandle = NewHandle(10L);
  87. memcpy(*sizehandle, &sizersc, 10);
  88. AddResource(sizehandle, 'SIZE', -1, "\pSwitcher/MF sizes");
  89. rc = ResError();
  90. if (rc != 0) {
  91.     printf("Error %d from AddResource.\n", rc);
  92.     CloseResFile(fref);
  93.     DisposHandle(sizehandle);
  94.     return(rc);
  95.     }
  96. sizehandle = GetResource('SIZE', -1);
  97. rc = ResError();
  98. if (rc != 0) {
  99.     printf("Error %d from GetResource.\n", rc);
  100.     CloseResFile(fref);
  101.     DisposHandle(sizehandle);
  102.     return(rc);
  103.     }
  104. sizeattrs = GetResAttrs(sizehandle);
  105. rc = ResError();
  106. if (rc != 0) {
  107.     printf("Error %d from GetResAttrs.\n", rc);
  108.     CloseResFile(fref);
  109.     DisposHandle(sizehandle);
  110.     return(rc);
  111.     }
  112. sizeattrs |= resPreload;
  113. SetResAttrs(sizehandle, sizeattrs);
  114. rc = ResError();
  115. if (rc != 0) {
  116.     printf("Error %d from SetResAttrs.\n", rc);
  117.     CloseResFile(fref);
  118.     DisposHandle(sizehandle);
  119.     return(rc);
  120.     }
  121. CloseResFile(fref);
  122. rc = ResError();
  123. if (rc != 0) {
  124.     printf("Error %d from CloseResFile.\n", rc);
  125.     }
  126. DisposHandle(sizehandle);
  127. return(rc);
  128. }
  129.